using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace LS.GameKit
{
    [CreateAssetMenu(menuName = "Lancer Studio/Sequence Clip", fileName = "New Sequence Clip")]
    public class SequenceClip : ScriptableObject
    {
        public int frameRate = 24;
        public WrapMode wrap = WrapMode.Once;
        public List<Sprite> sprites = new List<Sprite>();

        public int FrameCount
        {
            get
            {
                return sprites.Count;
            }
        }

        public float Length
        {
            get
            {
                return (1f / (float)frameRate) * (float)FrameCount;
            }
        }

        public Sprite GetFrame(int index)
        {
            if (sprites.Count <= 0) return null;

            int frame = Mathf.Clamp(index, 0, FrameCount - 1);
            return sprites[frame];
        }

        public Sprite GetFrameByTime(float time)
        {
            int id = Mathf.FloorToInt((time / Length) * FrameCount);
            return GetFrame(id);
        }
    }
}
